<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>04练习3_函数</title>
</head>

<body>
	<h1>简易计算器</h1>
	<input type="text" id="one" placeholder="请输入第一个数">
	<select id="symbol">
		<option value="+">+</option>
		<option value="-">-</option>
		<option value="*">*</option>
		<option value="/">/</option>
	</select>
	<input type="text" id="two" placeholder="请输入第二个数">
	<button id="btn">=</button>
	<input type="text" id="result" placeholder="结果">
</body>
<script src="tool.js"></script>
<script>
	// 编写一个函数，计算两个数字的和、差、积、商  calc(num1,num2,type)  
	var oBtn = document.getElementById("btn");
	// console.log(oBtn);
	var oOne = document.getElementById("one");
	var oTwo = document.getElementById("two");
	var oSymbol = document.getElementById("symbol");
	var oResult = document.getElementById("result");

	oBtn.onclick = function(){
		// alert(666);
		var oneVal = oOne.value;
		var twoVal = oTwo.value;
		var symbolVal = oSymbol.value;

		// console.log(oneVal,twoVal,symbolVal);打印是否拿到值

		var num = calc(oneVal,twoVal,symbolVal);//实参
		// console.log(num);
		oResult.value = num;//将num计算好的值赋值给result
	}







	//计算函数的封装

	// var num1 = "10";
	// var num2 = 4;
	// var type = "*";

	// var num = calc(10,2,"-");
	// console.log(num);


	// function calc(num1, num2, type) {
	// 	var res;
	// 	switch (type) {
	// 		case "+":
	// 			res = num1 * 1 + num2 * 1;
	// 			break;
	// 		case "-":
	// 			res = num1 - num2;
	// 			break;
	// 		case "*":
	// 			res = num1 * num2;
	// 			break;
	// 		case "/":
	// 			res = num1 / num2;
	// 			break;
	// 	}
	// 	return res;
	// }






</script>

</html>